//
//  Game.m
//  Mimik
//
//  Created by Mikkel Gravgaard on 18/12/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "Game.h"
#import "MimikViewController.h"

@implementation Game

@synthesize viewController;

- (id)init {
	
	return self;

}

- (void)newGame
{
	response = [[NSMutableArray alloc] initWithCapacity:0];
	challenge = [[NSMutableArray alloc] initWithCapacity:3];
	for(int i=0;i<3;i++){
		[self newNumber];
	}
	[viewController showChallenge:challenge];
}


- (void)newNumber{
	NSInteger gen = (arc4random() % 3);
	[challenge addObject:[NSNumber numberWithInteger:gen]];
}

- (void)respond:(NSInteger)number{
	NSLog(@"New response: %d",number);
	NSInteger challengeValue = [[challenge objectAtIndex:[response count]] integerValue];
	if(number==challengeValue){
		[response addObject:[NSNumber numberWithInteger:number]];
		NSLog(@"Response is correct!");
		if([response count]==[challenge count]){
			response = [[NSMutableArray alloc] initWithCapacity:0];
			[self newNumber];
			[viewController showChallenge:challenge];
		}
	} else {
		[viewController gameOver];
	}
	
}

- (void)dealloc
{
	[response dealloc];
	[super dealloc];

}

- (NSInteger)score{
   return [challenge count]-3;
}

@end
